// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "WinstonLogger.h"
#include "GameSettingsManager.generated.h"

/**
 * 游戏设置管理器
 * 作为游戏实例子系统，负责存储和管理游戏中的各种配置参数
 */
UCLASS()
class EMPTYLAND_API UGameSettingsManager : public UGameInstanceSubsystem
{
    GENERATED_BODY()

public:
    // 初始化子系统
    virtual void Initialize(FSubsystemCollectionBase& Collection) override;
    
    // 关闭子系统
    virtual void Deinitialize() override;

    /**
     * 获取游戏设置管理器单例
     * @param WorldContextObject 世界上下文对象
     * @return 游戏设置管理器实例
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings", meta = (WorldContext = "WorldContextObject"))
    static UGameSettingsManager* Get(const UObject* WorldContextObject);

    /**
     * 设置移动速度
     * @param NewWalkSpeed 行走速度
     * @param NewSprintSpeed 冲刺速度
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    void SetMovementSpeeds(float NewWalkSpeed, float NewSprintSpeed);

    /**
     * 获取行走速度
     * @return 行走速度
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    float GetWalkSpeed() const;

    /**
     * 获取冲刺速度
     * @return 冲刺速度
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    float GetSprintSpeed() const;

    /**
     * 设置相机灵敏度
     * @param NewSensitivity 相机灵敏度
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    void SetCameraSensitivity(float NewSensitivity);

    /**
     * 获取相机灵敏度
     * @return 相机灵敏度
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    float GetCameraSensitivity() const;

    /**
     * 加载设置
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    void LoadSettings();

    /**
     * 保存设置
     */
    UFUNCTION(BlueprintCallable, Category = "Game Settings")
    void SaveSettings();

private:
    // 行走速度
    UPROPERTY(EditDefaultsOnly, Category = "Movement Settings", meta = (AllowPrivateAccess = "true"))
    float WalkSpeed;

    // 冲刺速度
    UPROPERTY(EditDefaultsOnly, Category = "Movement Settings", meta = (AllowPrivateAccess = "true"))
    float SprintSpeed;

    // 相机灵敏度
    UPROPERTY(EditDefaultsOnly, Category = "Camera Settings", meta = (AllowPrivateAccess = "true"))
    float CameraSensitivity;

    /**
     * 应用设置
     * 将设置应用到游戏系统
     */
    void ApplySettings();
};